// rolling control
var _flag = false;
// current lines
var cur_size = 0 ;

/**
 * 行级标签滚动
 * @param lh 每行高度
 * @param speed 滚动速度
 * @param delay 间隔多少秒
 * @param targetId 元素id
 * @param url 请求地址
 */
function marquee(lh,speed,delay,targetId,url) {
    filldata(url,targetId);
    var obj = document.getElementById(targetId);
    obj.onmouseover = function (){_flag = true}
    obj.onmouseout = function (){_flag = false}
    obj.scrollTop = 0;

    function start(){
        if(cur_size> 0 ){
            _time_id = setInterval(scrolling,speed)
            if(!_flag){
                obj.scrollTop += 1;
            }
        }
    }

    function scrolling(){
        if(obj.scrollTop%lh != 0){
            obj.scrollTop += 1;
            if(obj.scrollTop >= obj.scrollHeight/2){
                obj.scrollTop = 0;
            }
        }else{
            clearInterval(_time_id);
            setTimeout("start()",delay);
        }
    }

    setTimeout("start()",delay);

}

function filldata(url,obj){
    $.ajax({
        type: "PSOT",
        url: url,
        dataType: "json",
        success: function(result){
            var lines = 0;
            $("#"+obj).empty();
            if(result.length>0){
                var objArray = new Array();
                objArray = result;
                for(var i=0;i<objArray.length;lines++){
                   newLi = "<ul><li><font color='red'>"+ objArray[lines]+"</font> </li></ul>"
                }
                $("#"+obj).append(newLi);
                $("#"+obj).html($("#"+obj).html()+$("#"+obj).html());
            }else{
                $("#"+obj).append("<ul><li><font color='green'>状态正常</font></li></ul>")
            }
            cur_size = lines;
        }
    });
}